import { createStore } from 'vuex'
import persist from 'vuex-persistedstate'
export default createStore({
  state: {
    checkIndex: 0,
    checkSty: 'all',
    shouList: [], // 收藏的数据
  },
  mutations: {
    storeTab(state,obj){
      state.checkIndex = obj.i;
      state.checkSty = obj.val;
    },
    add(state,val){ // 收藏的函数
      let index = state.shouList.findIndex(item => item.id == val.id);
      if (index>-1){
        state.shouList.splice(index,1);
      } else {
        state.shouList.push(val);
      }
      
    }
  },
  actions: {
  },
  modules: {
  },
  plugins: [
    new persist({
      storage: window.localStorage,
    }),
  ],
})
